<template>
	<view class="container">
		<view class="main">
			<view @click="handleOpenPage">
				<text>设置/忘记支付密码</text>
				<image src="/static/icon1/17.png" mode="aspectFill"></image>
			</view>
		</view>
		<view class="main">
			<view @click="handleOpenPage2">
				<text>账户注销</text>
				<view class="zu-desc">注销后账户无法恢复，请谨慎操作</view>
				<view>
					<image src="/static/icon1/17.png" mode="aspectFill"></image>
				</view>
			</view>
		</view>
		<view class="main">
			<view @click="changePhone">
				<text>更换手机号</text>
				<image src="/static/icon1/17.png" mode="aspectFill"></image>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				path: '', //设置完密码回哪里
			}
		},
		methods: {
			handleOpenPage2() {
				uni.navigateTo({
					url: '/pages/account-security/account-cancel'
				})
			},
			cancellation() {
				uni.showModal({
					title: '提示',
					content: '确定是否注销账号？',
					success: (res) => {
						if (res.confirm) {
							this.logOutUser();
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			//注销账户
			async logOutUser() {
				let res = await this.$fetch(this.$api.logOutUser, uni.getStorageSync('token'), 'POST')
				if (res.code == 0) {
					uni.removeStorageSync('userInfo');
					uni.removeStorageSync('token');
					uni.removeStorageSync('userType');
					uni.removeStorageSync('userId');
					uni.removeStorageSync('level');
					uni.removeStorageSync('first-is');
					uni.removeStorageSync('isHavePayPassword');
					uni.showToast({
						title: '账户已注销',
						icon: 'none'
					})
					setTimeout(() => {
						uni.switchTab({
							url: '/pages/index/index'
						})
					}, 600)
				} else {
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
				}
			},
			// 打开内页面
			handleOpenPage() {
				uni.navigateTo({
					url: '/pages/set-pay-code/set-pay-code?path=' + this.path
				})
			},
			changePhone() {
				uni.navigateTo({
					url: '/pages/change-phone/change-phone'
				})
			}
		},
		onLoad(options) {
			this.path = options.path
		}
	}
</script>

<style lang="less" scoped>
	.container {
		// border: 1px solid #000000;
		overflow: hidden;

		&>.main {
			margin-top: 30rpx;
			background-color: #FFFFFF;

			.zu-desc {
				// border: 1px solid;
				margin-right: -100rpx;
				font-size: 26rpx;
				color: #999;
			}

			&>view {
				padding: 30rpx;
				display: flex;
				align-items: center;
				justify-content: space-between;

				//height: 40rpx;
				image {
					width: 16rpx;
					height: 26rpx;
				}

				&::before {
					content: "";
					position: absolute;
					top: 130rpx;
					width: 720rpx;
					height: 2rpx;
					background: #F2F2F2;
					border-radius: 1px;
				}
			}
		}

	}
</style>
